import java.util.Arrays;
import java.util.List;

public class Solution1301 {
    public int[] pathsWithMaxScore(List<String> board) {
        board.set(0,board.get(0).replace("E","0"));
        int mod=1000000007;
        int[][] f=new int[board.size()][board.get(0).length()];
        int[][] g=new int[board.size()][board.get(0).length()];
        g[board.size()-1][board.get(0).length()-1]=1;
        for (int i=board.size()-1;i>=0;i--){
            for (int j=board.get(0).length()-1;j>=0;j--){
                if (g[i][j]!=1 && board.get(i).charAt(j)!='X'){
                    int max=0;
                    if (i!=board.size()-1 && board.get(i+1).charAt(j)!='X'){
                        max=Math.max(max,f[i+1][j]);
                    }
                    if (i!=board.size()-1 && j!=board.get(0).length()-1 && board.get(i+1).charAt(j+1)!='X'){
                        max=Math.max(max,f[i+1][j+1]);
                    }
                    if (j!=board.get(0).length()-1 && board.get(i).charAt(j+1)!='X'){
                        max=Math.max(max,f[i][j+1]);
                    }
                    f[i][j]=max+Integer.parseInt(board.get(i).charAt(j)+"");
                    if (i!=board.size()-1 && board.get(i+1).charAt(j)!='X'){
                        if (max==f[i+1][j]){
                            g[i][j]=(g[i][j]+g[i+1][j])%mod;
                        }
                    }
                    if (i!=board.size()-1 && j!=board.get(0).length()-1 && board.get(i+1).charAt(j+1)!='X'){
                        if (max==f[i+1][j+1]){
                            g[i][j]=(g[i][j]+g[i+1][j+1])%mod;
                        }
                    }
                    if (j!=board.get(0).length()-1 && board.get(i).charAt(j+1)!='X'){
                        if (max==f[i][j+1]){
                            g[i][j]=(g[i][j]+g[i][j+1])%mod;
                        }
                    }
                }
            }
        }
        if (g[0][0]==0){
            return new int[]{0,0};
        }
        return new int[]{f[0][0],g[0][0]};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1301().pathsWithMaxScore(Arrays.asList("EX","XS"))));
    }
}
